import { GoodsItem } from "../../common/GoodsItem";
import { DragEvent } from "../../../../../com/mui/events/DragEvent";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Cache } from "../../../cache/Cache";
import { ShopOperType } from "../../shop/ShopOperType";
import { CursorManager } from "../../../manager/CursorManager";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemMenuRegister } from "../../common/menu/ItemMenuRegister";
import { BaseItem } from "../../common/BaseItem";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { PetEquipUtil } from "../../common/util/PetEquipUtil";
import { PetUtil } from "../info/PetUtil";
//class PetEquipBaseItem
    
    export  class PetEquipBaseItem extends GoodsItem
    {
        constructor()
        {
            super();
            this.addEventListener(DragEvent.Event_Move_In, this.moveInHandler);
            this.addEventListener(DragEvent.Event_Throw_goods, this.throwHandler);
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClick);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOver);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOut);
            setOverPosition(-1, -1);
            return;
        }

        /* internal  */onMouseClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this._canOper || !itemData) 
            {
                return;
            }
            if (arg1.ctrlKey && itemData) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChatShowItem, itemData));
                arg1.stopImmediatePropagation();
                return;
            }
            if (itemData && Cache.instance.shop.operType == ShopOperType.FIX) 
            {
                arg1.stopImmediatePropagation();
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopFixEquipment, {"posType": itemData.posType, "itemData": itemData}));
            }
            return;
        }

        /* internal  */onMouseOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!itemData) 
            {
                return;
            }
            var loc1=Cache.instance.shop.operType;
            switch (loc1) 
            {
                case ShopOperType.FIX:
                {
                    CursorManager.showCursor(CursorManager.FIX);
                    break;
                }
            }
            return;
        }

        /* internal  */onMouseOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            CursorManager.showCursor(CursorManager.NO_CURSOR);
            return;
        }

        public /* override */ set itemData(arg1: ItemData)
        {
            super.itemData = arg1;
            this.checkPetLevel();
            if (arg1) 
            {
                ItemMenuRegister.register(this, arg1);
            }
            else 
            {
                ItemMenuRegister.unRegister(this);
            }
            return;
        }

        public set canOper(arg1: Boolean)
        {
            this._canOper = arg1;
            if (this._canOper && itemData) 
            {
                ItemMenuRegister.register(this, itemData);
            }
            else 
            {
                ItemMenuRegister.unRegister(this);
            }
            return;
        }

        public get canOper(): Boolean
        {
            return this._canOper;
        }

        /* internal  */moveInHandler(arg1: DragEvent): void
        {
            var loc1=null;
            if (!this._canOper) 
            {
                return;
            }
            if (arg1.dragItem is BaseItem && arg1.dragSouce is ItemData) 
            {
                loc1 = arg1.dragSouce as ItemData;
                if (loc1.category == ECategory._ECategoryPetEquip && !(loc1.uid == "") && !ItemsUtil.isDressInPet(loc1)) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetEquipDress, loc1));
                }
            }
            return;
        }

        /* internal  */throwHandler(arg1: DragEvent): void
        {
            var loc1=null;
            if (!this._canOper) 
            {
                return;
            }
            if (typeof arg1.dragSouce === "itemdata") 
            {
                loc1 = arg1.dragSouce as ItemData;
                if (loc1.category == ECategory._ECategoryPetEquip && !(loc1.uid == "") && ItemsUtil.isDressInPet(loc1)) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetEquipUndress, loc1));
                }
            }
            return;
        }

        /* internal  */checkPetLevel(): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=0;
            var loc4=0;
            if (itemData) 
            {
                loc1 = PetEquipUtil.getPetIdByPoseType(itemData.posType);
                loc2 = Cache.instance.pet.getPetInfoByPetId(loc1);
                loc3 = PetUtil.getRebornTimes(itemData.itemInfo.item.level);
                loc4 = PetUtil.getLevel(itemData.itemInfo.item.level);
                if (loc2 && (loc2.reinLevel < loc3 || loc2.reinLevel == loc3 && loc2.level < loc4)) 
                {
                    this.meetCareer = true;
                }
                else 
                {
                    this.meetCareer = false;
                }
            }
            else 
            {
                this.meetCareer = false;
            }
            return;
        }

        /* internal */ /* var */_canOper: Boolean;
    }
